import json


def query_production_volume(db_engine, volume_type):
    variables = ""
    if volume_type == 'assembly':
        variables = "'H55.DayTarget', 'H55.B55.F0_CURRENT', 'H55.F0_Actual', 'H55.C55.F0.diff'," \
                    " 'A55.F1.Dayvolume', 'H55.B55.F1_CURRENT', 'H55.F1_Actual', 'H55.C55.F1_DIFF_PUSH'," \
                    " 'A55.F2_target', 'H55.B55.F2_CURRENT', 'H55.F2_Actual', 'H55.C55.F2.diff', '52F0DTAR'," \
                    " 'H52 F0 Current Target', 'apipsp71.PPE092', '52F0DIFF', '52DTARGE', 'H52 F1 Current Target', 'apipsp71.PPE083'," \
                    " 'A812DIFF', 'F2DAYTAR', 'F2CURTAR', 'apipsp71.PPE086', 'A912DIFF'," \
                    " '50DTARF0', 'H50F0TAR', 'apipsp71.PPE089', 'H50DRDIS'," \
                    " '50DTARF1', 'H50F1TAR', 'apipsp71.PPE080', 'A811DIFF'," \
                    " 'H50_F0_Day_display', 'H50F0CurrentTarget', 'apipsp71.PPE089', 'H50F0RED'," \
                    " 'H50_F1_Day_display', 'H50F1CurrentTarget', 'apipsp71.PPE080', 'H50F1RED'," \
                    " 'G08TDTAR', 'G08F2TAR', 'apipsp71.PPE086', 'H50H52F2'"
    elif volume_type == 'paint':
        variables = "'NEX_Bodyshop_Daily_Target_', 'NEX_Bodyshop_Daily_Actual_Target_', 'Daily_Target.PS_OUT'," \
                    " 'Daily_Target_Current.PS_OUT', '319114Z1._PLC.CVI.M0025', 'H55.DayTarget'," \
                    " 'H55.B55.F0_CURRENT', 'H55.F0_Actual', 'H55.C55.F0.diff', 'NBE_Bodyshop_Daily_Target_MF'," \
                    " 'NBE_Bodyshop_Daily_Actual_Target_MF', 'NBE_Bodyshop_Daily_Volume_MF'," \
                    " 'Daily_Target.PS_IN.G08', 'Daily_Target_Current.PS_IN.G08', 'apipsp71.EVP306'," \
                    " 'Daily_Target.PS_IN', '319200Z1.SG01.CVI.PZ03', 'Daily_Target_Current.PS_IN'," \
                    " 'Daily_Target.PS_OUT.G08', 'Daily_Target_Current.PS_OUT.G08', 'apipsp71.EVP307'," \
                    " '52F0DTAR', 'H50DRDIS', 'apipsp71.PPE092', '52F0DIFF', 'NEX_Bodyshop_MF1_Daily_Volume'," \
                    " 'NEX_Bodyshop_MF2_Daily_Volume', 'apipsp71.PPE089', 'H50F0TAR', 'H52 F0 Current Target',"\
                    " '50DTARF0', 'NBS_Bodyshop_Daily_Volume_MF', 'NBS_Bodyshop_Daily_Actual_Target_MF', 'NBS_Bodyshop_Daily_Target_MF'"
    elif volume_type == 'body':
        variables = "'NEX_Bodyshop_Daily_Target_UBS', 'NEX_Bodyshop_Daily_Actual_Target_UBS'," \
                    " 'NEX_Bodyshop_UBS_Daily_Volume', 'NEX_Bodyshop_Daily_Target_UB'," \
                    " 'NEX_Bodyshop_Daily_Actual_Target_UB', 'NEX_Bodyshop_UB_Daily_Volume'," \
                    " 'NEX_Bodyshop_Daily_Target_FR', 'NEX_Bodyshop_Daily_Actual_Target_FR'," \
                    " 'NEX_Bodyshop_FR_Daily_Volume', 'NEX_Bodyshop_Daily_Target_'," \
                    " 'NEX_Bodyshop_Daily_Actual_Target_', 'NBE_Bodyshop_Daily_Target_UBS'," \
                    " 'NBE_Bodyshop_Daily_Actual_Target_UBS', 'NBE_Bodyshop_Daily_Volume_UBS'," \
                    " 'NBE_Bodyshop_Daily_Target_UB', 'NBE_Bodyshop_Daily_Actual_Target_UB'," \
                    " 'NBE_Bodyshop_Daily_Volume_UB', 'NBE_Bodyshop_Daily_Target_FR3S'," \
                    " 'NBE_Bodyshop_Daily_Actual_Target_FR3S', 'NBE_Bodyshop_Daily_Volume_FR3S'," \
                    " 'NBE_Bodyshop_Daily_Target_MF', 'NBE_Bodyshop_Daily_Actual_Target_MF'," \
                    " 'NBE_Bodyshop_Daily_Volume_MF', 'NEX_Bodyshop_MF1_Daily_Volume'," \
                    " 'NEX_Bodyshop_MF2_Daily_Volume', 'NBS_Bodyshop_Daily_Target_UBS'," \
                    "'NBS_Bodyshop_Daily_Actual_Target_UBS', 'NBS_Bodyshop_Daily_Volume_UBS'," \
                    "'NBS_Bodyshop_Daily_Target_UB', 'NBS_Bodyshop_Daily_Actual_Target_UB'," \
                    "'NBS_Bodyshop_Daily_Volume_UB', 'NBS_Bodyshop_Daily_Target_FR3S'," \
                    "'NBS_Bodyshop_Daily_Actual_Target_FR3S', 'NBS_Bodyshop_Daily_Volume_FR3S'," \
                    "'NBS_Bodyshop_Daily_Target_MF', 'NBS_Bodyshop_Daily_Actual_Target_MF'," \
                    "'NBS_Bodyshop_Daily_Volume_MF'"
    data_dict = {}
    if variables:
        sql = "SELECT value_symbol,value_num FROM p_values WHERE value_symbol IN (%s)" % variables
        query_data = db_engine.execute(sql)
        for row in query_data:
            idx = row[0]
            val = row[1]
            data_dict[idx] = val
    return json.dumps(data_dict)
